/**
 * Created with IntelliJ IDEA.
 * User: liulinhui
 * Date: 18-10-9
 * Time: 上午10:31
 * Description: chainApi
 */
import chainApi from '@/utils/request';
import request from 'request'

/**
 * 获取用户资产
 * @param token token name:DATX,DBTC等
 * @param address  用户地址
 * @returns {*}
 */
export function getTokenBalance(token, address) {
  return chainApi({
    url: '/token_balance',
    method: 'post',
    data: {
      token: token,
      address: address
    }
  })
}

/**
 * 根据DATx地址查询资产（代币list）
 * @param category DATX
 * @param address DATX地址
 */
export function getWalletBalance(category, address) {
  return chainApi({
    url: '/wallet_balance',
    method: 'post',
    data: {
      category: category,
      address: address
    }
  })
}

/**
 * 绑定链外钱包
 * @param datxaddress
 * @param address
 */
export function mapAddress(datxaddress, address) {
  return chainApi({
    url: '/address_map',
    method: 'post',
    data: {
      datxaddress: datxaddress,
      address: address
    }
  })
}

/**
 * 查询资产成交记录
 * @param category 资产
 * @param address 地址
 * @param limit 条数
 * @returns {*}
 */
export function getWalletTrxList(category, address, limit) {
  return chainApi({
    url: '/wallet_trx_list',
    method: 'post',
    data: {
      category: category,
      address: address,
      limit: limit
    }
  })
}

/**
 * 创建DATX钱包
 * @param obj obj
 * @returns {*}
 */
export function newAccount(obj) {
  return chainApi({
    url: '/new_account',
    method: 'post',
    data: obj
  })
}

/**
 * 获取用户已抵押资源
 * @param account 用户名  code:200表示账户存在，500表示不存在
 */
export function getResource(account) {
  return chainApi({
    url: '/resource',
    method: 'post',
    data: {
      account: account
    }
  })
}

/**
 * 根据公钥查询用户名字
 * @param publicKey 用户公钥
 */
export function getAccountByPublicKey(publicKey) {
  return chainApi({
    url: '/get_accounts',
    method: 'post',
    data: {
      public_key: publicKey
    }
  })
}

/**
 * 除BTC之外充值
 * @param unit  //货币名称 "BTC" "ETH"
 * @param datxaddress  //DATx账号
 * @param address  //ETH地址
 * @param method:"GET" 获取是否已经充值，SET发送充值
 */


export function rechargeDatx(method,unit,datxaddress,address) {
  return chainApi({
    url: '/address_map',
    method: 'post',
    data: {
      method:method,
      category:unit,
      datxaddress: datxaddress,
      address: address
    }
  })
}

/**
 * 用户投票状态
 * @param account

 */
export function getVoteState(account) {
  return chainApi({
    url: '/get_votes',
    method: 'post',
    data: {
      account:account
    }
  })
}

/**
 * 获取超级节点（投票详情）
 * @param

 */
export function getVote() {
  return chainApi({
    url: '/get_bps',
    method: 'post',
    data: {
    }
  })
}


